<%--taken from uploadbean examples --%>
<%@ page language="java" import="javazoom.upload.*,java.util.*" %>
<%@ page errorPage="ExceptionHandler.jsp" %>
<%@ include file="header.jsp" %>
<% 
String os = System.getProperty("os.name").toLowerCase();
boolean isWindows = (os.indexOf( "win" ) >= 0);
String uploadpath = isWindows?"C:/uploads/":"/Users/mkwuuuu/uploads/";
out.println(uploadpath);
%>
<jsp:useBean id="upBean" scope="page" class="javazoom.upload.UploadBean" >
  <jsp:setProperty name="upBean" property="folderstore" value="<%=uploadpath%>" />
</jsp:useBean>

    <hr class="noscreen" />
<ul class="style1">
<%
      if (MultipartFormDataRequest.isMultipartFormData(request))
      {
         // Uses MultipartFormDataRequest to parse the HTTP request.
         MultipartFormDataRequest mrequest = new MultipartFormDataRequest(request);
         String todo = null;
         if (mrequest != null) todo = mrequest.getParameter("todo");
	     if ( (todo != null) && (todo.equalsIgnoreCase("upload")) )
	     {
                Hashtable files = mrequest.getFiles();
                if ( (files != null) && (!files.isEmpty()) )
                {
                    UploadFile file = (UploadFile) files.get("uploadfile");
                    int index = file.getFileName().lastIndexOf('.');
                    String ext = file.getFileName().substring(index);
                    file.setFileName(session.getAttribute("userID")+ext);
                    upBean.setOverwrite(true);
                    if (file.getContentType().equals("image/jpeg") && file != null){
                    	upBean.store(mrequest, "uploadfile");%>
                    	<meta HTTP-EQUIV="REFRESH" content="0; url=profile.jsp">
                    	
<%                  } else
					out.println(file.getContentType());
                	out.println("Please select jpg file");
			
                    // Uses the bean now to store specified by jsp:setProperty at the top.
                }
                else
                {
                  out.println("<li>No uploaded files");
                }
	     }
         else out.println("<BR> todo="+todo);
      }
%>
</ul>
<form method="post" action="upload.jsp" name="upform" enctype="multipart/form-data">
  <table width="60%" border="0" cellspacing="1" cellpadding="1" align="center" class="style1">
    <tr>
      <td align="left"><b>Select a file to upload :</b></td>
    </tr>
    <tr>
      <td align="left">
        <input type="file" name="uploadfile" size="50">
        </td>
    </tr>
    <tr>
      <td align="left">
		<input type="hidden" name="todo" value="upload">
        <input type="submit" name="Submit" value="Upload">
        </td>
    </tr>
  </table>
</form>
<%@ include file="footer.jsp" %>